using System.Web;
using System.Web.Mvc;

namespace MvcWinesSample
{
    public class AllowCrossSiteJsonAttribute : ActionFilterAttribute
    {

        //http://stackoverflow.com/questions/7001846/how-to-handle-options-method-in-asp-net-mvc

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {

            //HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            //HttpContext.Current.Response.Cache.SetNoStore();

            //filterContext.RequestContext.HttpContext.Response.AppendHeader("Access-Control-Allow-Origin", "*");

            //string rqstMethod = HttpContext.Current.Request.Headers["Access-Control-Request-Method"];
            //if (rqstMethod == "OPTIONS")
            //{
            //    filterContext.RequestContext.HttpContext.Response.AppendHeader("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS");
            //    filterContext.RequestContext.HttpContext.Response.AppendHeader("Access-Control-Allow-Headers", "X-Requested-With, Accept, Access-Control-Allow-Origin, Content-Type");
            //}
            //base.OnActionExecuting(filterContext);
        }
    }
}